#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>

class ThreadNum1
{
public:
    ThreadNum1()//构造函数
    {
        thread_num_ = -1;
    }
    ~ThreadNum1()//析构函数
    {

    }
    void SetThreadNum(int num)
    {
        thread_num_ = num;
    }
    int GetThreadNum()
    {
        return thread_num_;
    }
private:
    int thread_num_;
};

void* MyThreadStart(void* arg)
{
    ThreadNum1* tn = (ThreadNum1*)arg;
    while(1)
    {
        printf("MyThreadStart:%d\n",tn->GetThreadNum());
        sleep(1);
    }
    delete tn;
    return NULL;
}

int main()
{
    pthread_t tid;
    for(int i = 0;i < 2;i++ )
    {
        ThreadNum1* tn = new ThreadNum1();
        tn->SetThreadNum(i);
        int ret = pthread_create(&tid,NULL,MyThreadStart,(void*)tn);
        if(ret != 0)
        {
            perror("pthread_create");
            return 0;
        }
    }
    while(1)
    {
        printf("i am main thread\n");
        sleep(1);
    }
    return 0;
}
